package com.epichust.bootumpp.controller;

import com.epichust.bootumpp.config.NotIntercept;
import com.epichust.bootumpp.model.bo.ReturnBO;
import com.epichust.bootumpp.model.entity.Mbf5ProduceOpMresource;
import com.epichust.bootumpp.model.entity.Mbf5ProduceOperation;
import com.epichust.bootumpp.service.IMbf5ProduceOpMresourceService;
import com.epichust.bootumpp.service.IMbf5ProduceOperationService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 产品工序控制层
 */
@RestController
@RequestMapping("/umpp/Mbf5ProduceOperation")
public class Mbf5ProduceOperationController {

    @Autowired
    public IMbf5ProduceOperationService iMbf5ProduceOperationService;

    @Autowired
    public IMbf5ProduceOpMresourceService iMbf5ProduceOpMresourceService;

    /**
     * 通过参数查询产品工序
     */
    @RequestMapping(value = "/getAllByParams", method = {RequestMethod.POST})
    @NotIntercept
    public String getAllByParams(@RequestBody Map<String,String> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            List<Mbf5ProduceOperation> list= iMbf5ProduceOperationService.getAllByParams(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            bo.setObject(gson.toJson(list));
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("查询失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }

    /**
     * 新增修改产品工序
     */
    @RequestMapping(value = "/saveOrUpdate", method = {RequestMethod.POST})
    @NotIntercept
    public String saveOrUpdate(@RequestBody Map<String,String> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            iMbf5ProduceOperationService.saveOrUpdate(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("保存失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }

    /**
     * 删除、激活、冻结 产品工序
     */
    @RequestMapping(value = "/common", method = {RequestMethod.POST})
    @NotIntercept
    public String common(@RequestBody Map<String,String> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            String rel = iMbf5ProduceOperationService.common(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            bo.setObject(rel);
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("查询失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }
    /**
     * 通过参数查询产品工序-工位资源
     */
    @RequestMapping(value = "/getOpEresourceByParams", method = {RequestMethod.POST})
    @NotIntercept
    public String getOpEresourceByParams(@RequestBody Map<String,String> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            List<Map> list= iMbf5ProduceOperationService.getOpEresourceByParams(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            bo.setObject(gson.toJson(list));
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("查询失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }

    /**
     * 保存产品工序-工位资源
     */
    @RequestMapping(value = "/saveOpEresource", method = {RequestMethod.POST})
    @NotIntercept
    public String saveOpEresource(@RequestBody Map<String,String> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            iMbf5ProduceOperationService.saveOpEresource(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("保存失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }
    /**
     * 通过参数查询产品工序-工装资源
     */
    @RequestMapping(value = "/getOpMresourceByParams", method = {RequestMethod.POST})
    @NotIntercept
    public String getOpMresourceByParams(@RequestBody Map<String,String> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            List<Mbf5ProduceOpMresource> list= iMbf5ProduceOpMresourceService.getOpMresourceByParams(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(0);
            bo.setObject(gson.toJson(list));
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("查询失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }

    /**
     * 保存产品工序-工装资源
     */
    @RequestMapping(value = "/saveOpMresource", method = {RequestMethod.POST})
    @NotIntercept
    public String saveOpMresource(@RequestBody Map<String,String> map) throws Exception{
        try{
            // 新建返回对象
            Gson gson = new GsonBuilder().serializeNulls().create();
            iMbf5ProduceOpMresourceService.saveOpMresource(map);
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("ceshi");
            return gson.toJson(bo);
        }catch(Exception e){
            e.printStackTrace();
            Gson gson = new GsonBuilder().serializeNulls().create();
            ReturnBO bo = new ReturnBO();
            bo.setState(1);
            bo.setObject("保存失败："+e.getMessage());
            return gson.toJson(bo);
        }
    }
}
